#include "FindPwdMobileVerifyDlg.h"

#include <core/ImageMgr.h>
#include <core/StyleMgr.h>
#include <widgets/SLineEdit.h>

#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpacerItem>
#include <QVBoxLayout>
#include <QWidget>

FindPwdMobileVerifyDlg::FindPwdMobileVerifyDlg(QWidget* p /*= nullptr*/)
    : QWidget(p) {
  QVBoxLayout* vL = new QVBoxLayout(this);
  vL->setContentsMargins(0, 0, 0, 0);
  QLabel* phoneVerify = new QLabel(tr("手机验证"), this);
  vL->addWidget(phoneVerify, 0, Qt::AlignLeft);
  vL->addSpacing(14);
  m_mobileNumberEdit = new SLineEdit("", this);
  m_mobileNumberEdit->setSelectAllWhenFocus(true);
  m_mobileNumberEdit->setFixedSize(382, 38);
  m_mobileNumberEdit->setPlaceholderText(tr("请输入手机号"));
  QFont f = m_mobileNumberEdit->font();
  f.setPixelSize(15);
  m_mobileNumberEdit->setFont(f);
  vL->addWidget(m_mobileNumberEdit, 0, Qt::AlignLeft);
  vL->addSpacing(18);

  QHBoxLayout* inputCodeLayout = new QHBoxLayout();
  m_verifyCode = new SLineEdit("", this);
  m_verifyCode->setSelectAllWhenFocus(true);
  m_verifyCode->setFixedSize(238, 38);
  m_verifyCode->setPlaceholderText(tr("请输入验证码"));
  m_verifyCode->setFont(f);
  inputCodeLayout->addWidget(m_verifyCode, 0, Qt::AlignLeft);
  inputCodeLayout->addSpacing(8);

  m_getCodeButton = new QPushButton();
  m_getCodeButton->setFixedSize(136, 40);
  m_getCodeButton->setText(tr("获取验证码"));
  m_getCodeButton->setFont(f);
  inputCodeLayout->addWidget(m_getCodeButton, 0, Qt::AlignLeft);
  vL->addLayout(inputCodeLayout);
}

QrAndLabelWidget::QrAndLabelWidget(QWidget* p /*= nullptr*/) : QWidget(p) {
  QHBoxLayout* QrCodeAndTextLayout = new QHBoxLayout(this);
  QrCodeAndTextLayout->setContentsMargins(0, 0, 0, 0);

  QSpacerItem* spHItem = new QSpacerItem(40, 0);
  QrCodeAndTextLayout->addSpacerItem(spHItem);

  QLabel* wechatQrcodeLabel = new QLabel(this);
  SImage* qrCodeImg = ImgMgr::instance().image(
      "auth_wechat_offical_qrcode", WidgetStatus::kNormal, devicePixelRatioF());
  if (qrCodeImg) wechatQrcodeLabel->setPixmap(QPixmap::fromImage(*qrCodeImg));
  QrCodeAndTextLayout->addWidget(wechatQrcodeLabel);

  QrCodeAndTextLayout->addSpacing(2);

  QVBoxLayout* vL = new QVBoxLayout();
  vL->setContentsMargins(0, 0, 0, 0);
  QSpacerItem* spVItem = new QSpacerItem(0, 38);
  vL->addSpacerItem(spVItem);

  QLabel* scanTxtLabel = new QLabel();
  QFont f = scanTxtLabel->font();
  f.setPixelSize(12);
  scanTxtLabel->setFont(f);
  scanTxtLabel->setStyleSheet(
      QString("color:#%1")
          .arg(StyleMgr::instance().color("SupportingWord").rgb(), 0, 16));
  scanTxtLabel->setText(
      tr("扫描二维码，关注公众号，联系运营人员\n客服热线: (86) 021 60202726"));
  vL->addWidget(scanTxtLabel);

  QrCodeAndTextLayout->addLayout(vL);
}
